package com.sgb.member.view_model

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.sgb.member.MemberConfig
import com.sgb.member.entity.*
import com.swgk.core.base.api.ICallBack
import com.swgk.core.base.model.entity.BaseEntity

class MemberChooseMemberPriceModel : ViewModel() {
    var msgLiveData = MutableLiveData<String>()
    var isLoadLiveData = MutableLiveData<Boolean>()
    var dataListLiveData = MutableLiveData<List<MemberBean2>>()

    fun getMemberList(comType:String,keyWord:String) {
        isLoadLiveData.postValue(true)
        val map = mutableMapOf<String, Any>()
        map.put("memberType", comType)//1企业 2个人
        map.put("name", keyWord)
        map.put("relation", 1)//只查需方

        MemberConfig.getInstance().api.getMemberList(map).enqueue(object : ICallBack<BaseEntity<List<MemberBean2>>?>() {
            override fun onSuccess(data: BaseEntity<List<MemberBean2>>?) {
                isLoadLiveData.postValue(false)
                if (data?.data != null) {
                    dataListLiveData.postValue(data.data)
                }
            }

            override fun onFail() {
                super.onFail()
                isLoadLiveData.postValue(false)
            }
        })
    }

}